﻿using Api.Application.Command.Leave;
using Api.DTO;
using ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    /// <summary>
    /// 请假审批控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class LeaveController : ControllerBase
    {
        private readonly IMediator mediator;

        public LeaveController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 请假审批显示
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回受影响行数</returns>
        [HttpGet]
        public Task<ApiPaging<LeaveDTO>> GetLeave([FromQuery]GetLeaveCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 请假审批添加 http://localhost:5011/api/Leave/AddLeave
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public Task<ApiResult<int>> AddLeave(AddLeaveCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 请假审批删除
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回受影响行数</returns>
        [HttpGet]
        public Task<ApiResult<int>> DelLeave([FromQuery] DelLeaveCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 请假审批修改
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public Task<ApiResult<int>> UpdateLeave(UpdateLeaveCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 请假审批接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateStatu(UpdateStatuCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
